package com.company.project.file.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.AssertUtil;
import com.company.project.file.po.FileParameterConfig;
import com.company.project.file.service.FilePathConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName FilePathConfigController
 * @Author sherry
 * @Date 2025/3/2 11:20
 * @Description FilePathConfigController
 * @Version 1.0
 */
@RequestMapping("/file")
@RestController
@Api(tags = "文件配置模块-文件路径管理")
public class FilePathConfigController {
    
    @Resource
    private FilePathConfigService pathConfigService;

    @GetMapping("/pathConfigs/tree")
    @ApiOperation(value = "树型文件配置列表接口")
    @LogAnnotation(title = "机构管理", action = "树型组织列表")
    @SaCheckPermission(value = {"file:pathConfig:allList", "file:pathConfig:updateByInstId", "file:pathConfig:selectByInstId"}, mode = SaMode.OR)
    public List<FileParameterConfig> getTree() {
        return pathConfigService.selectAll();
    }


    @GetMapping("/pathConfigs")
    @ApiOperation(value = "查询全部文件路径信息接口")
    @LogAnnotation(title = "文件路径管理", action = "查询全部文件路径信息接口")
/*
    @SaCheckPermission("file:pathConfig:allList")
*/
    public List<FileParameterConfig> selectAll() {
        return pathConfigService.selectAll();
    }

    
    @PutMapping("/pathConfig/updateByInstId/{instId}")
    @ApiOperation(value = "更新文件路径信息接口")
    @LogAnnotation(title = "文件路径管理", action = "更新文件路径信息")
    @SaCheckPermission("file:pathConfig:updateByInstId")
    public void updateByInstId(@PathVariable("instId") String instId) {
        AssertUtil.isStringNotBlank(instId, "id不能为空");
        pathConfigService.updateByInstId(instId);
    }

    @GetMapping("/pathConfig/{instId}")
    @ApiOperation(value = "查询单个文件路径详情接口")
    @LogAnnotation(title = "文件路径管理", action = "查询单个文件路径详情")
    @SaCheckPermission("file:pathConfig:selectByInstId")
    public FileParameterConfig selectByInstId(@PathVariable("instId") String instId) {
        return pathConfigService.selectByInstId(instId);
    }


}
